package com.boboPlanet.config;


import com.boboPlanet.service.GatewayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.Set;

/**
 * Sentinel、route
 * @Description: 动态路由配置
 * @Author: mis_wu
 * @Date: 2022/4/30
 * 限流规则放入预加载中
 * 此处不用限流代码,限流在网关中配置即可
 **/
@Slf4j
@Component
public class GatewayConfigApplicationRunner implements ApplicationRunner {

    @Autowired
    private GatewayService gatewayService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        initAllGatewayRouteConfig();
    }


    /**
     * 网关路由初始化配置
     */
    private void initAllGatewayRouteConfig(){
        // 动态路由  或yml配置二选一
         gatewayService.loadAllRoutes();
        log.info(Thread.currentThread().getName()+" 网关route配置初始化成功...");
    }
}
